using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Controls;
using System.Globalization;

namespace ValidationFramework
{
    /// <summary>
    /// Validates the length of the binding value
    /// </summary>
    public class LengthValidationRule: ValidationRuleBase
    {
        #region Private Fields
        
        private int _minLength;
        private int _maxLength;

        #endregion

        /// <summary>
        /// Validates if the length of the value is between the minimum length and maximum length
        /// </summary>
        /// <param name="value"></param>
        /// <param name="cultureInfo"></param>
        /// <returns></returns>
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            string textValue = value.ToString();
            ValidationResult result = new ValidationResult(true,null);

            if(textValue.Length < _minLength || textValue.Length > _maxLength)
            {
                result = new ValidationResult(false, ErrorMessage);
            }

            return result;
        }

        #region Public Properties
        
        /// <summary>
        /// Gets or sets the minimum length of the value
        /// </summary>
        public int MaxLength
        {
            get { return _maxLength; }
            set { _maxLength = value; }
        }

        /// <summary>
        /// Gets or sets the maximum length of the value
        /// </summary>
        public int MinLength
        {
            get { return _minLength; }
            set { _minLength = value; }
        } 

        #endregion

    }
}
